# Copyright (C) 2015 Romain Perier
# Released under the MIT license (see COPYING.MIT for the terms)

inherit kernel
require recipes-kernel/linux/linux-yocto.inc

SRC_URI = "git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git;nobranch=1 \
	file://0001-ARM-dts-rockchip-enable-gmac-on-rk3288-firefly.patch \
	file://defconfig"

SRCREV = "39a8804455fb23f09157341d3ba7db6d7ae6ee76"
# Override this variable in order to don't pass --noallconfig to configme,
# which restarts configuration from scratch most of the time
KCONFIG_MODE = " "
LINUX_VERSION = "4.0"
# Override local version in order to use the one generated by linux build system
# And not "yocto-standard"
LINUX_VERSION_EXTENSION = ""
PR = "r1"
PV = "${LINUX_VERSION}"

PROVIDES = "${PN}"
DEPENDS += "rkflashtool-native"

# Include only supported boards for now
COMPATIBLE_MACHINE = "(radxarock|marsboard-rk3066|firefly-rk3288)"

# Build the devicetree blob in kernel_do_compile
KERNEL_ALT_IMAGETYPE = "${KERNEL_DEVICETREE}"
# The resulting image to be deployed in DEPLOY_IMAGE_DIR
KERNEL_OUTPUT = "${B}/arch/${ARCH}/boot/${KERNEL_IMAGETYPE}-dtb"

KERNEL_IMAGE_BASE_NAME = "RK3XPetitbootLoader-${PV}-${MACHINE}"
KERNEL_IMAGE_SYMLINK_NAME = "RK3XPetitbootLoader-${MACHINE}"

INITRAMFS_IMAGE = "petitboot-initramfs-image"
INITRAMFS_TASK = "${INITRAMFS_IMAGE}:do_rootfs"

do_compile_append() {
    cat ${B}/arch/${ARCH}/boot/${KERNEL_IMAGETYPE} ${B}/arch/${ARCH}/boot/dts/${KERNEL_ALT_IMAGETYPE} > ${KERNEL_OUTPUT}
}

do_deploy_append() {
    rkcrc -k ${DEPLOYDIR}/${KERNEL_IMAGE_BASE_NAME}.bin ${DEPLOYDIR}/${KERNEL_IMAGE_BASE_NAME}.img
    mv ${DEPLOYDIR}/${KERNEL_IMAGE_BASE_NAME}.img ${DEPLOYDIR}/${KERNEL_IMAGE_BASE_NAME}.bin
}
